use util;
use crate::container;

pub mod con;
pub mod file;
pub mod error;
pub mod recipe;
pub mod version;
pub mod segment;
pub mod pointer;
pub mod fp_pointer;

pub use con::*;
pub use file::*;
pub use error::*;
pub use recipe::*;
pub use version::*;
pub use segment::*;
pub use pointer::*;
pub use fp_pointer::*;

use crate::constants;

pub mod recipe_tests {
    use super::*;

    pub fn test() -> RecipeResult<()> {
    	let test_list = vec![
    		FileInfo::new(1,2,"linux".to_string()),
    		FileInfo::new(4,5,"destor".to_string()),
    	]; 
        let mut frw = FileRecipeWriter::from_path(&"./test.FileRecipe")?;
        for f in test_list.iter() {
        	frw.append(f)?;
        }
        drop(frw);
        let mut frr = FileRecipeReader::from_path(&"./test.FileRecipe")?;
        let mut result_list = Vec::new();
        loop {
        	let f = frr.get()?;
        	match f {
        		Some(f) => {
        			println!("{:#?}",f);
        			result_list.push(f);
        		}
        		None => {
        			break
        		}
        	}
        }
        assert_eq!(test_list.len(),result_list.len());
        for (a,b) in test_list.iter().zip(result_list.iter()) {
        	assert_eq!(a,b.as_ref());
        }
        
    	let test_list:Vec<container::ContainerId> = vec![
    		4,1,2,3
    	]; 
        let mut frw = ConRecipeWriter::from_path(&"./test.ConRecipe")?;
        for &f in test_list.iter() {
        	frw.append(f)?;
        }
        drop(frw);
        let mut frr = ConRecipeReader::from_path(&"./test.ConRecipe")?;
        let mut result_list = Vec::new();
        loop {
        	let f = frr.get()?;
        	match f {
        		Some(f) => {
        			println!("{}",f);
        			result_list.push(f);
        		}
        		None => {
        			break
        		}
        	}
        }
        assert_eq!(test_list.len(),result_list.len());
        for (a,b) in test_list.iter().zip(result_list.iter()) {
        	assert_eq!(a,b);
        }
        
        Ok(())
    }
}
